package jp.co.htkk.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jp.co.htkk.dto.${TableName!}Dto;
import jp.co.htkk.dto.UserDto;
import jp.co.htkk.form.${TableName!}RegisterForm;
import jp.co.htkk.service.${TableName!}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import static jp.co.htkk.common.CommonConst.*;

@RestController
@Tag(name = "${TableName!}Controller", description = "${TableName!} related APIs")
public class ${TableName!}Controller {

    @Autowired
    private ${TableName!}Service ${tableName!}Service;


    /**
     * Used for register new ${tableName!}
     *
     * @param ${tableName!}RegisterForm
     * @return jp.co.htkk.dto.${TableName!}Dto
     * @throws
     **/
    @Operation(summary = "Used for register new ${tableName!}")
    @PostMapping(REGISTER_${TABLENAME!})
    public ${TableName!}Dto ${tableName!}Register(@Valid @RequestBody ${TableName!}RegisterForm ${tableName!}RegisterForm) {
        return ${tableName!}Service.register(${tableName!}RegisterForm);
    }
    /**
     * Get ${tableName!} by ID
     * @param id
     * @return jp.co.htkk.dto.${TableName!}Dto
     * @throws
     **/
    @Operation(summary = "Used for get ${tableName!} by id")
    @GetMapping(SEARCH_${TABLENAME!}_BY_ID)
    public ${TableName!}Dto get${TableName!}ById(@PathVariable("id") String id) {
        return ${tableName!}Service.get${TableName!}ById(id);
    }
    /**
     * Delete ${tableName!} by id
     * @param id
     * @return jp.co.htkk.dto.${TableName!}Dto
     * @throws
     **/
    @Operation(summary = "Delete user by id")
    @DeleteMapping(DELETE_${TABLENAME!}_BY_ID)
    public ${TableName!}Dto delete${TableName!}ById(@PathVariable("id") String id) {
        return ${tableName!}Service.delete${TableName!}ById(id);
    }

    /**
     * Update ${tableName!}
     *
     * @param ${tableName!}Dto
     * @return jp.co.htkk.dto.${TableName!}Dto
     * @throws
     **/
    @Operation(summary = "Update ${tableName!}")
    @PutMapping(UPDATE_${TABLENAME!})
    public ${TableName!}Dto update${TableName!}(@RequestBody ${TableName!}Dto ${tableName!}Dto) {
        return ${tableName!}Service.update${TableName!}(${tableName!}Dto);
    }
}
